package uk.co.q3c.deplan.client.domain.task;

import uk.co.q3c.deplan.client.domain.util.DateProfileEntry;
import uk.co.q3c.deplan.client.domain.util.DateProfileEntryBase;
import uk.co.q3c.deplan.client.service.ServiceFactory;

import com.googlecode.objectify.annotation.Cached;
import com.googlecode.objectify.annotation.Unindexed;

/**
 * @see PlanDailyProfile
 * @author David Sowerby 19 Feb 2010
 * 
 */
@Unindexed
@Cached(expirationSeconds = 600)
public class PlanProfileEntry extends DateProfileEntryBase implements DateProfileEntry {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int workDone;
	private int workLeft;
	private int workPlanned;

	protected PlanProfileEntry() {
		super();
	}

	public PlanProfileEntry(ServiceFactory connection, String dateKey) {
		super(dateKey);
	}

	public int getWorkDone() {

		return workDone;
	}

	public void setWorkDone(int done) {

		this.workDone = done;
	}

	public int getWorkLeft() {

		return workLeft;
	}

	public void setWorkLeft(int left) {

		this.workLeft = left;
	}

	/**
	 * Overrides the current value of work left, but without calling the parent task back (as this method is invoked by the parent a loop
	 * would result)
	 * 
	 * @param workLeft
	 */
	public void forceLeft(int workLeft) {

		this.workLeft = workLeft;

	}

	@Override
	public String toString() {

		return "PlanProfileEntry " + getDateKey() + " planned=" + Integer.toString(workPlanned) + " done=" + Integer.toString(workDone) + " left="
				+ Integer.toString(workLeft);
	}

	public void addToDone(int workDone) {

		setWorkDone(this.workDone + workDone);

	}

	public void setWorkPlanned(int planned) {

		this.workPlanned = planned;
	}

	public int getWorkPlanned() {
		return workPlanned;
	}

	/**
	 * Increases the work planned by effortWanted
	 * 
	 * @param effortWanted
	 */
	public void bookEffort(int effortWanted) {
		setWorkPlanned(getWorkPlanned() + effortWanted);

	}

}
